import java.util.*;


public class Solution {
    /**
     * 代码中的类名、方法名、参数名已经指定，请勿修改，直接返回方法规定的值即可
     *
     * 
     * @param n int整型 
     * @return int整型
     */
    public int findNthDigit (int n) {
        // write code here

        // int index = -1;
        Stack<Integer> stack = new Stack<>();

        // 超时
        /*
        for (int i = 0; ; i++) {
            int temp = i;
            do {
                stack.push(temp % 10);
                temp /= 10;
            } while (temp > 0);
            while (!stack.isEmpty()) {
                index++;
                temp = stack.pop().intValue();
                if (index == n)
                    return temp;
            }
        }
        */

        // 超时
        /*
        for (int i = 0; ; i++) {
            String s = i + "";
            // System.out.println(s.length());
            if (index + s.length() < n)
                index += s.length();
            else {
                int size = s.length();
                index = n - index;
                // System.out.println(index);
                return s.charAt(index - 1) - '0';
            } 
            
        }
        */

        int digit = 1;
        long start = 1;
        long sum = 9;
        while (sum < n) {
            digit++;
            start *= 10;
            n -= sum;
            sum = 9 * start * digit;
        }
        String num = "" + (start + (n - 1)/digit);
        int index = (n - 1) % digit;
        return num.charAt(index) - '0';

    }
}